import { DataTypes, Model } from 'sequelize'
import { sequelize } from '../../connect'
import { findAllValues, findOneValue, findOneRandomValue } from '../../public'

type ModelProps = {
  id: number
  name: string
  type: string // 技能类型
  attribute: string // 技能属性
  distance: number // 技能距离
  module: string // 技能模组
  power: number // 技能威力
  mp_cost: number // 技能蓝耗
  cd: number // 技能冷却时间
  effect: string // 技能效果数组[]
  description: string // 技能描述
}

class skill_list extends Model<ModelProps> {
  public static findAllValues = findAllValues
  public static findOneValue = findOneValue
  public static findOneRandomValue = findOneRandomValue
}

skill_list.init(
  {
    id: {
      type: DataTypes.BIGINT,
      primaryKey: true,
      allowNull: false,
      autoIncrement: true,
      comment: '技能ID'
    },
    name: {
      type: DataTypes.STRING(50),
      allowNull: false,
      unique: true,
      comment: '技能名称'
    },
    type: {
      type: DataTypes.STRING(20),
      allowNull: false,
      comment: '技能类型'
    },
    attribute: {
      type: DataTypes.STRING(20),
      allowNull: false,
      comment: '技能属性'
    },
    distance: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 1,
      comment: '技能距离'
    },
    module: {
      type: DataTypes.STRING(50),
      allowNull: false,
      comment: '技能模组'
    },
    power: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '技能威力'
    },
    mp_cost: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '技能蓝耗'
    },
    cd: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '技能冷却时间'
    },
    effect: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: '技能效果'
    },
    description: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: '技能描述'
    }
  },
  {
    sequelize,
    tableName: 'skill_list',
    freezeTableName: true,
    createdAt: false,
    updatedAt: false,
    indexes: [
      {
        unique: true,
        fields: ['id']
      },
      {
        unique: true,
        fields: ['name']
      }
    ]
  }
)

export { skill_list }
